/**
 * 模型拖拽上图功能示意
 */
import { clearLayers } from "@/common/uses/use-layer"

let Cesium

/**
 * @type DE.Viewer
 */
let viewer // 地图对象

/**
 *
 * @param {DE.Viewer} mapInstance
 */
// 初始化当前业务
export function onMounted (mapInstance) {
  viewer = mapInstance // 记录map
  Cesium = DE.getLib("Cesium")
}

// 释放当前业务
export function onUnmounted () {
  viewer = null
  Cesium = null
}

export function deploySatellite (satelliteList) {
  const startTime = new Date("2023-02-14T08:00:00")
  const endTime = new Date("2023-02-15T08:00:00")
  const interval = {
    startTime,
    endTime,
    currentTime: startTime
  }
  window?.$dmapLayerManager.removeLayerByGroupId("satelliteLayer")
  satelliteList.forEach((tle) => {
    const czml = DE.Util.tle2czml(tle, interval)
    const layerCfg = {
      name: tle.name,
      id: tle.name,
      type: "CZML",
      url: czml,
      groupId: "satelliteLayer"
    }
    window?.$dmapLayerManager.registerLayer(layerCfg)
  })

  /* 模拟卫星，非真实卫星轨迹 */
  // scanning(czml)
}
